import java.io.*;
import java.util.*;
import java.util.Scanner;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;

public class Access extends JPanel
{
	//File temp = new File ("fileDB");
	//String path = temp.getAbsolutePath();

	private JLabel pwString;
	private JPasswordField pwTF;
	private JButton sign;
  private JButton sign_2;
  private JButton sign_3;

	private boolean getAccessed = false;

	
	
	public Access ()
	{
		setBackground (Color.white);
		setLayout (new BoxLayout (this, BoxLayout.X_AXIS));

		pwString = new JLabel ("PW : ");
		pwTF = new JPasswordField (12);
			pwTF.setBackground (new Color (252,245,245));
			pwTF.setEchoChar ('*');

		sign = new JButton (" Sing In ");
			sign.setPreferredSize (new Dimension (70, 45));
			sign.setBackground (Color.white);
			sign.setBorder (BorderFactory.createLineBorder (new Color (255, 238, 238), 4));
			sign.addActionListener (new EventsListener());

		add (pwString);
		add (pwTF);
		add (sign);		
	}



	private class EventsListener implements ActionListener
	{
		public void actionPerformed (ActionEvent event)
		{
			if (event.getSource() == sign)
			{
				String enteredPW = pwTF.getText ();

				try
				{
					Scanner infoscan = new Scanner (new File ("password.txt"));
						infoscan.useDelimiter ("&&&&");

					String password = infoscan.next();

					if (enteredPW.equals(password))
						getAccessed = true;
					else
					{
						JOptionPane.showMessageDialog (null, "The password you entered is worng. Try again, please");
						pwTF.setText("");
					}
				}	catch (IOException ioe)	 {	}
			}
		}
	}

	public void textfield_reset ()	{	pwTF.setText("");	}

	public boolean getGetAccessed ()	 {	return getAccessed;	 }
	public void resetGetAccessed ()	 {	getAccessed = false;	}
}